package com.jiuqi.irs.action.account;


import java.util.Properties;    
    
import javax.mail.Message;    
import javax.mail.Session;    
import javax.mail.Transport;    
import javax.mail.internet.InternetAddress;    
import javax.mail.internet.MimeMessage;    
    
public class SendMail {    
    
    private static final String MAIL_USER = "liuyangyao521";     
        
    private static final String MAIL_PASSWORD = "123456";    
        
    private static final String MAIL_FROM = "liuyangyao521@163.com";     
        
        
    /**  
     */    
    public static void sendMail(String mail,String subject,String text) {    
    
        try {    
            Properties props = new Properties();    
            props.put("mail.smtp.host", "smtp.163.com");    
            props.put("mail.smtp.auth", "true");    
            Session ssn = Session.getInstance(props, null);    
            MimeMessage message = new MimeMessage(ssn);    
            InternetAddress fromAddress = new InternetAddress(MAIL_FROM);    
            message.setFrom(fromAddress);    
            InternetAddress toAddress = new InternetAddress(mail);    
            message.addRecipient(Message.RecipientType.TO, toAddress);    
            message.setSubject(subject);    
            message.setText(text);    
            Transport transport = ssn.getTransport("smtp");    
            transport.connect("smtp.163.com", MAIL_USER, MAIL_PASSWORD);    
            transport.sendMessage(message, message    
                    .getRecipients(Message.RecipientType.TO));    
            transport.close();    
            System.out.println("222");    
        } catch (Exception m) {    
            System.out.println(m.toString());    
        }    
    }    
        
    /**  
     * @param user     
     */    
    public static void sendMail(String user,String password,String from ,String mail,String subject,String text) {    
    
        try {    
            Properties props = new Properties();    
            props.put("mail.smtp.host", "smtp.163.com");    
            props.put("mail.smtp.auth", "true");    
            Session ssn = Session.getInstance(props, null);    
            MimeMessage message = new MimeMessage(ssn);    
            InternetAddress fromAddress = new InternetAddress(from);    
            message.setFrom(fromAddress);    
            InternetAddress toAddress = new InternetAddress(mail);    
            message.addRecipient(Message.RecipientType.TO, toAddress);    
            message.setSubject(subject);    
            message.setText(text);    
            Transport transport = ssn.getTransport("smtp");    
            transport.connect("smtp.163.com", user, password);    
            transport.sendMessage(message, message    
                    .getRecipients(Message.RecipientType.TO));    
            transport.close();    
            System.out.println("1111111");    
        } catch (Exception m) {    
            System.out.println(m.toString());    
        }    
    }    
        
        
    /**  
     * @param args  
     */    
    public static void main(String[] args) {    
        for(int i = 0; i < 20; i++) {    
            sendMail("yangyao.liu@gmail.com", "1111", "3333331111");    
        }    
    }    
    
}  